package command

import (
	"gitee.com/sansaniot/ssiot-core/httpmvc/jwtauth/user"
	"github.com/gin-gonic/gin"
	"ssadmin/common/constant"
)

type UserInfo struct {
	UserId     string
	UserName   string
	DeptIdList []string
	DeptId     string
	CreatorId  string
	AgencyId   string
}

func (e *UserInfo) LoadUser(c *gin.Context) {
	e.UserId = user.Get(c, constant.CacheKeyUserId).(string)
	e.UserName = user.Get(c, constant.CacheKeyUserName).(string)
	agencyId := user.Get(c, constant.CacheKeyAgencyId)
	if agencyId != nil {
		e.AgencyId = agencyId.(string)
	}
	//获取对应的创建人信息
	creatorId := user.Get(c, constant.CacheKeyCreatorId)
	if creatorId != nil {
		e.CreatorId = creatorId.(string)
	}
}

//admin用户创建的都是租户 admin本身也属于租户
func (e *UserInfo) IsTenant() bool {
	//获取创建人
	if e.CreatorId == "1" {
		return true
	} else {
		return false
	}
}
